package com.pet.config;

import com.pet.shop.intercepters.AppSecurityInterceptor;
import com.pet.shop.intercepters.WebLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 *
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {

    /**
     * 配置拦截器
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AppSecurityInterceptor()).addPathPatterns("/api/**")
                .excludePathPatterns("/api/open/**", "/web/monitor/videoShow",
                        "/api/user/wxAuth", "/api/advert/**", "/api/upload/**");
        registry.addInterceptor(new WebLoginInterceptor()).addPathPatterns("/web/**")
                .excludePathPatterns("/web/monitor/videoShow", "/web/login", "/web/logout");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry ) {
        registry.addViewController("/" ).setViewName( "forward:/WEB-INF/jsp/manage/login.jsp" );
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE );
        super.addViewControllers(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");
        super.addResourceHandlers(registry);
    }
}
